package com.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;
@WebFilter(filterName = "codeFilter",urlPatterns="/*",initParams = {@WebInitParam(name = "encoding",value = "UTF-8")})
public class CodeFilter implements Filter {
    private String encoding="iso8859-1";
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding=filterConfig.getInitParameter("encoding");
    }
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        filterChain.doFilter(request,response);
    }
    public void destroy() {

    }
}
